﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Downloader
{
    public partial class NewTaskForm : Form
    {
        public string url;
        public string filename;
        public string dirname;
        public bool isok;

        public NewTaskForm()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            isok = false;
            this.Close();
        }

        private void NewTaskForm_Load(object sender, EventArgs e)
        {
            if (Clipboard.ContainsText())
            {
                if (Clipboard.GetText().StartsWith("http://") || Clipboard.GetText().StartsWith("ftp://"))
                {
                    string url = Clipboard.GetText();
                    int p2 = url.LastIndexOf('?');
                    int p1 = url.LastIndexOf('/');
                    if (p2==-1 || p2<p1)
                    {

                        p2 = url.Length;
                    }

                    textBox1.Text = url;
                    textBox2.Text = url.Substring(p1 + 1, p2-p1-1);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            url = textBox1.Text;
            filename = textBox2.Text;
            dirname = textBox3.Text;
            isok = true;
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.ShowDialog(this);
            dialog.ShowNewFolderButton = true;
            this.textBox3.Text = dialog.SelectedPath;
        }
    }
}
